<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ECharts</title>
    <!-- 引入 echarts.js -->
    <script src="js/echarts.min.js"></script>
    <script src="js/jquery-3.5.1.js" ></script>
    <script  src="js/china.js" ></script>
</head>
<body>
    <!-- 为ECharts准备一个具备大小（宽高）的容器 -->
    <div id="chart" style="width: 100%; height: 550px"></div>
    
    <script>   
            //初始化
            var myChart = echarts.init(document.getElementById('chart'));
              
               //读取微博JSON数据
                $.getJSON('weibo.json', function (weiboData) {
                   
                  //定义一个Data方法将读取的微博数据根据经纬度组合成新的JSON，用于显示
                    Data = function (index) {
                        data = weiboData[index];
                        // 坐标数据是横纵坐标值的1000倍，所以需要除以1000
                        var px = data[0] / 1000;
                        var py = data[1] / 1000;
                        var res = [[px, py]];
              
                        for (var i = 2; i < data.length; i += 2) {
                            var dx = data[i] / 1000;
                            var dy = data[i + 1] / 1000;
                            var x = px + dx;
                            var y = py + dy;
                            res.push([x, y, 1]);
              
                            px = x;
                            py = y;
                        }
                        return res;
                    };
                  
                  //设置参数
                    myChart.setOption(
                    option = {
                        backgroundColor: '#404a59',
                        title: {         //标题设置
                            text: '微博签到数据点亮中国',
                            subtext: 'From ThinkGIS',
                            left: 'center',
                            top: 'top',
                            textStyle: {
                                color: '#fff'
                            }
                        },
                        legend: {        //图例设置
                            left: 'left',
                            data: ['强', '中', '弱'],
                            textStyle: {
                                color: '#ccc'
                            }
                        },
                        geo: {           //地理坐标系设置
                            name: '强',
                            type: 'scatter',
                            map: 'china',
                            label: {
                                emphasis: {
                                    show: false
                                }
                            },
                            itemStyle: {
                                normal: {
                                    areaColor: '#323c48',
                                    borderColor: '#111'
                                },
                                emphasis: {
                                    areaColor: '#2a333d'
                                }
                            }
                        },
                        series: [{             
                            name: '弱',
                            type: 'scatter',
                            coordinateSystem: 'geo',
                            symbolSize: 1,
                            large: true,
                            itemStyle: {
                                normal: {
                                    shadowBlur: 2,
                                    shadowColor: 'rgba(37, 140, 249, 0.8)',
                                    color: 'rgba(37, 140, 249, 0.8)'
                                }
                            },
                            data: Data(0)
                        }, {
                            name: '中',
                            type: 'scatter',
                            coordinateSystem: 'geo',
                            symbolSize: 1,
                            large: true,
                            itemStyle: {
                                normal: {
                                    shadowBlur: 2,
                                    shadowColor: 'rgba(14, 241, 242, 0.8)',
                                    color: 'rgba(14, 241, 242, 0.8)'
                                }
                            },
                            data: Data(1)
                        }, {
                            name: '强',
                            type: 'scatter',
                            coordinateSystem: 'geo',
                            symbolSize: 1,
                            large: true,
                            itemStyle: {
                                normal: {
                                    shadowBlur: 2,
                                    shadowColor: 'rgba(255, 255, 255, 0.8)',
                                    color: 'rgba(255, 255, 255, 0.8)'
                                }
                            },
                            data: Data(2)
                        }]
                    });
                });
</script>
   
</body>
</html>